<template>
  <div>
    <div>
      <maigua
        v-for="(item, index) in goodsArr"
        :key="index"
        :obj="item"
        :index="index"
      ></maigua>
    </div>
    <p>All Number: {{ Sum }}</p>
  </div>
</template>

<script>
import maigua from "./components/买瓜.vue";
export default {
  components: {
    maigua,
  },
  data() {
    return {
      goodsArr: [
        {
          count: 0,
          goodsName: "Watermelon",
        },
        {
          count: 0,
          goodsName: "Banana",
        },
        {
          count: 0,
          goodsName: "Orange",
        },
        {
          count: 0,
          goodsName: "Pineapple",
        },
        {
          count: 0,
          goodsName: "Strawberry",
        },
      ],
    };
  },
  computed: {
    Sum() {
      // console.log(this.goodsArr[0].count);
      return this.goodsArr.reduce((sum, obj) => (sum += obj.count), 0);
    },
  },
};
</script>

<style>
</style>